<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>操作节点</title>
    <style>
        .child{
            width: 100px;
            height: 100px;
            margin: 10px;
            background-color: red;
        }
    </style>
    <script>
        window.onload=function(){
            //获取父节点
            var parent=document.getElementsByClassName('parent')[0];
            // 新建一个节点
            var newChild=document.createElement('div')
            newChild.innerHTML='<div class="child">newChild</div>';
            // 获取参考节点
            var two=parent.children[1];
            // 进行节点插入
            //插入节点 insertBerfore（插入的节点，参考节点）
            // parent.insertBefore(newChild,two);
            
            //替换节点 replacechild (插入的节点，替换的节点)
            parent.replaceChild(newChild,two);
            //移除节点 removechild
            var three=parent.children[2];
            parent.removeChild(three);
            //获取节点内容
            console.log(parent.innerHTML,'识别代码片段');
            console.log(parent.innerText,'只识别文本 去除空格和回车');
            console.info(parent.textContent,'只识别文本，不去除空格和回车');

            //清空节点内部内容
            parent.innerHTML='';
        }
    </script>
</head>
<body>
    <div class="parent">
        <div class="child">one</div>
        <div class="child">two</div>
        <div class="child">three</div>
    </div>
</body>
</html>